<?php

namespace Org\Com;

class Evaluation
{
    /**
     *  通过买家的 ID 获取买家的信用值
     * @param type $buyer_id
     * @return type
     */
    function get_buyer_evaluation($buyer_id){
        if(empty($buyer_id))
            return;

            $step = intval(C('upgrade_required'));
            $step < 1 && $step = 5;
            
            $member_info  = M('Member')->where('user_id='.$buyer_id)->find();
            $data['buyer_credit_value'] = $member_info['buyer_credit_value'];
            $member_info['portrait'] ? $data['buyer_credit_image'] = $member_info['portrait'] : '';
//            $data['buyer_credit_image'] = 'data/system/buyer_evaluation/' .$this->compute_member_credit($member_info['buyer_credit_value'],$step);
            $data['buyer_praise_rate']  = $member_info['buyer_praise_rate'];
        return $data;
    }

    /**
     * 根据买家信用值计算图标
     *
     * @param   int     $credit_value   信用值
     * @param   int     $step           最低等级升级所需信用值
     * @return  string  图片文件名
     */
    function compute_member_credit($credit_value, $step = 5) {
        $step < 1 && $step = 5;
        
        if (C('b_level') != 'true') {
            $level_1 = $step * 5;
            $level_2 = $level_1 * 6;
            $level_3 = $level_2 * 6;
            $level_4 = $level_3 * 6;
            $level_5 = $level_4 * 6;
            if ($credit_value < $level_1) {
                return 'b_red_' . (floor($credit_value / $step) + 1) . '.gif';
            } elseif ($credit_value < $level_2) {
                return 'b_blue_' . (floor(($credit_value - $level_1) / $level_1) + 1) . '.gif';
            } elseif ($credit_value < $level_3) {
                return 'b_blue_' . (floor(($credit_value - $level_2) / $level_2) + 1) . '.gif';
            } else {
                return 'b_red_1.gif';
            }
        }else{
            $member_credit = 'b_red_1.gif';
            switch ($credit_value) {
                case $credit_value>=intval(C('b_level_1_from'))&&$credit_value<intval(C('b_level_1_to')):
                    $member_credit = 'b_red_1.gif';
                    break;
                case $credit_value>=intval(C('b_level_2_from'))&&$credit_value<intval(C('b_level_2_to')):
                    $member_credit = 'b_red_2.gif';
                    break;
                case $credit_value>=intval(C('b_level_3_from'))&&$credit_value<intval(C('b_level_3_to')):
                    $member_credit = 'b_red_3.gif';
                    break;
                case $credit_value>=intval(C('b_level_4_from'))&&$credit_value<intval(C('b_level_4_to')):
                    $member_credit = 'b_red_4.gif';
                    break;
                case $credit_value>=intval(C('b_level_5_from'))&&$credit_value<intval(C('b_level_5_to')):
                    $member_credit = 'b_red_5.gif';
                    break;
                case $credit_value>=intval(C('b_level_6_from'))&&$credit_value<intval(C('b_level_6_to')):
                    $member_credit = 'b_blue_1.gif';
                    break;
                case $credit_value>=intval(C('b_level_7_from'))&&$credit_value<intval(C('b_level_7_to')):
                    $member_credit = 'b_blue_2.gif';
                    break;
                case $credit_value>=intval(C('b_level_8_from'))&&$credit_value<intval(C('b_level_8_to')):
                    $member_credit = 'b_blue_3.gif';
                    break;
                case $credit_value>=intval(C('b_level_9_from'))&&$credit_value<intval(C('b_level_9_to')):
                    $member_credit = 'b_blue_4.gif';
                    break;
                case $credit_value>=intval(C('b_level_10_from'))&&$credit_value<intval(C('b_level_10_to')):
                    $member_credit = 'b_blue_5.gif';
                    break;
                case $credit_value>=intval(C('b_level_11_from'))&&$credit_value<intval(C('b_level_11_to')):
                    $member_credit = 'b_cap_1.gif';
                    break;
                case $credit_value>=intval(C('b_level_12_from'))&&$credit_value<intval(C('b_level_12_to')):
                    $member_credit = 'b_cap_2.gif';
                    break;
                case $credit_value>=intval(C('b_level_13_from'))&&$credit_value<intval(C('b_level_13_to')):
                    $member_credit = 'b_cap_3.gif';
                    break;
                case $credit_value>=intval(C('b_level_14_from'))&&$credit_value<intval(C('b_level_14_to')):
                    $member_credit = 'b_cap_4.gif';
                    break;
                case $credit_value>=intval(C('b_level_15_from'))&&$credit_value<intval(C('b_level_15_to')):
                    $member_credit = 'b_cap_5.gif';
                    break;
                default:
                    break;
            }
            return $member_credit;
        }
    }
}

?>